// cf-gym-100570-e
// 题意：
// 给定一个长度为n(<=10^5)的字符串，现在有三种操作：
//  1. 1 p x：将s[p] 修改为x；
//  2. 2 p: 询问最长的回文子串的长度S[l..r], 且r-p=p-l；
//  3. 2 p: 询问最长的回文子串的长度S[l..r], 且r-p-1=p-l；
//
// 题解：
// 使用robin-carp，其实就是一个指数形式的哈兮。
// 如果用哈兮来做，这题就水了，用个树状数组就行。
//
// ml:run = $bin < input
#include <iostream>
#include <algorithm>
#include <string>

using ll = long long;
ll const mo = 999999997;
ll const p = 9997;
int const maxn = 100009;
ll tree[maxn];
ll tree2[maxn];
ll pow[maxn];
std::string s;
int n;

int lowbit(int x) { return x & -x; }

void update(int id, ll v, ll tree[])
{
    for (; id <= n; id += lowbit(id))
        tree[id] = (tree[id] + v) % mo;
}

void init()
{
    n = s.size();
    ll tmp = 1;
    pow[0] = 1;
    for (int i = 1; i <= n; i++) {
        tmp = ((s[i - 1] - 'a') * pow[i - 1]) % mo;
        pow[i] = (pow[i - 1] * p) % mo;
        update(i, tmp, tree);
        tmp = ((s[n - i] - 'a') * pow[i - 1]) % mo;
        update(n - i + 1, tmp, tree2);
    }
}

ll sum(int id, ll tree[])
{
    ll ret = 0;
    for (; id > 0; id -= lowbit(id)) ret = (ret + tree[id]) % mo;
    return ret;
}

bool judge(int l1, int r1, int l2, int r2)
{
    if (r2 > n) return false;
    ll t1 = (sum(r1,  tree) - sum(l1 - 1,  tree) + mo) % mo;
    ll t2 = (sum(r2, tree2) - sum(l2 - 1, tree2) + mo) % mo;
    int max = std::max(l1 - 1, n - r2);
    if (l1 - 1 < max) t1 = (t1 * pow[max - (l1 - 1)]) % mo;
    if (n - r2 < max) t2 = (t2 * pow[max - (n - r2)]) % mo;
    return t1 == t2;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int q;
    std::cin >> s >> q;
    init();
    for (int i = 0; i < q; i++) {
        int opt, p; std::cin >> opt >> p;
        if (opt == 1) {
            char ch; std::cin >> ch;
            ll delta = ((ch - s[p - 1]) * pow[p - 1]) % mo;
            delta = (delta + mo) % mo;
            update(p, delta, tree);

            delta = ((ch - s[p - 1]) * pow[n - p]) % mo;
            delta = (delta + mo) % mo;
            update(p, delta, tree2);

            s[p - 1] = ch;
        } else if (opt == 2) {
            int l = 1, r = p;
            while (l + 1 < r) {
                int mid = (l + r) / 2;
                if (judge(mid, p, p, p + p - mid)) r = mid;
                else l = mid;
            }
            if (judge(l, p, p, p + p - l)) r = l;
            std::cout << 2 * (p - r) + 1 << "\n";
        } else {
            int l = 1, r = p;
            while (l + 1 < r) {
                int mid = (l + r) / 2;
                if (judge(mid, p, p + 1, p + 1 + p - mid)) r = mid;
                else l = mid;
            }
            if (judge(l, p, p + 1, p + 1 + p - l)) r = l;
            if (!judge(r, p, p + 1, p + 1 + p - r))
                std::cout << "-1\n";
            else
                std::cout << 2 * (p - r) + 2 << "\n";
        }
    }
}

